<template>
  <div class="tabbar">
    <template v-for="(item, index) in tabbarData" key="item.text">
      <div
        class="tab-item"
        @click="tabClick(index, item)"
        :class="{ active: currentIndex === index }"
      >
        <img
          v-if="currentIndex !== index"
          :src="getAssetURL(item.image)"
          alt="获取失败"
        />
        <img v-else :src="getAssetURL(item.imageActive)" alt="获取失败" />
        <span class="text">{{ item.text }}</span>
      </div>
    </template>
  </div>
</template>

<script setup>
import { ref } from "vue"
import { useRouter } from "vue-router"

import tabbarData from "@/assets/data/tabbar"
import { getAssetURL } from "@/utils/load_assets"

const currentIndex = ref(0)
const router = useRouter()
const tabClick = (index, item) => {
  currentIndex.value = index
  router.push(item.path)
}
</script>

<style lang="less" scoped>
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50px;
  display: flex;
  background-color: #fff;
  // z-index: 9;

  border-top: 1px solid #f3f3f3;
  .tab-item {
    flex: 1;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    display: flex;
    &.active {
      color: var(--primary-color);
    }

    img {
      width: 28px;
    }
    .text {
      font-size: 12px;
    }
  }
}
</style>
